package com.example.yls.bmob;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;

public class MainActivity extends AppCompatActivity {
    private Button btnReg;
    private Button btnLogin;
    private Button btnUserInfo;
    private Button btnOUT;
    private Button btnPhone;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnLogin = findViewById(R.id.btn_login);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,LoginActivity.class);
                startActivity(intent);
            }
        });
        btnReg = findViewById(R.id.btn_reg);
        btnReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,RegActivity.class);
                startActivity(intent);
            }
        });
        btnPhone = findViewById(R.id.btn_phone);
        btnPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,PhoneActivity.class);
                startActivity(intent);
            }
        });
        btnUserInfo = findViewById(R.id.btn_user_info);
        btnUserInfo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(BmobUser.getCurrentUser()==null){
                    Toast.makeText(MainActivity.this,"请您登录", Toast.LENGTH_SHORT).show();
                }else{
                    Myuser myuser = BmobUser.getCurrentUser(Myuser.class);
                    final String info = myuser.getUsername()+ myuser.getName()+ myuser.getAge();

                    Toast.makeText(MainActivity.this,"用户信息" +info, Toast.LENGTH_SHORT).show();
}
            }
        });
        btnOUT = findViewById(R.id.btn_out);
        btnOUT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BmobUser.logOut();
            }
        });
    }
}
